package com.thread.practice;

public class NewThread implements Runnable {
	Thread t;

	public NewThread() {
		// 创建一个新的线程
		t = new Thread(this, "Demo Thread");
		System.out.println("Chlid thread:" + t);
		t.start();
	}

	@Override
	public void run() {
		for (int i = 0; i < 5; i++) {
			System.out.println("ChildThread" + i);
			try {
				Thread.sleep(1000);

			} catch (InterruptedException e) {
				// 如果其他线程试图中断这个正在休眠的线程就会抛出这个异常
				System.out.println("Child Interrupted");
			}
		}
		System.out.println("非主线程已关闭");
	}
}
